//企业联系人 显示表格及js实体

Ext.define('CompanyLinkman', {
    extend: 'Ext.data.Model',
    fields: [
        "Id"
		, "CompanyId"   //企业Id
		, "CompanyName"   //企业名称
		, "Department"   //部门
		, "EmpId"   //联系人Id
		, "EmpName"   //联系人姓名
		, "Position"   //职务
		, "Title"   //称谓
		, "Email"   //联系邮箱
		, "OfficialTel"   //办公电话
		, "OfficialMobile"   //办公移动电话
		, "SuperiorPositon"   //上级职务
		, "SuperiorName"   //上级姓名
		, "Remark"   //备注
	],
    idProperty: "Id"
});

Ext.define('SHApp.CompanyManage.CompanyLinkman.Grid', {
    extend: 'BLBTSystem.grid',
    alias: 'shapp.companymanage.grid',
    requires: ['SHApp.CompanyManage.CompanyLinkman.Form',
    'SHApp.EmployeeInfo.BasicInfo.CompanyComboBox',
    'SHApp.CompanyManage.CompanyLinkman.EmployeeComboBox'],
    txtCompanyNameID: 'txtCompanyName',
    txtEmpNameID: 'txtEmpName',
    dataModel: "CompanyLinkman",
    dataUrl: "api/companylinkman?format=json",
    initComponent: function () {
        var me = this;
        Ext.apply(this);
        me.btnAddID += me.id;
        me.btnEditID += me.id;
        me.btnDeleteID += me.id;
        me.txtCompanyNameID += me.id;
        me.txtEmpNameID += me.id;
        this.creatTbar();
        this.creatColumns();
        this.callParent(arguments);
        this.checkBtnPermission(me.pvalue);
    },
    creatColumns: function () {
        var me = this;
        me.columns = [{
            text: "联系人职务",
            width: 100,
            dataIndex: 'Position',
            sortable: true
        }, {
            text: "联系人姓名",
            width: 100,
            dataIndex: 'EmpName',
            sortable: true
        }, {
            text: "办公电话",
            width: 120,
            dataIndex: 'OfficialTel',
            sortable: true
        }, {
            text: "办公移动电话",
            width: 120,
            dataIndex: 'OfficialMobile',
            sortable: true
        }, {
            text: "联系邮箱",
            width: 150,
            dataIndex: 'Email',
            sortable: true
        }, {
            text: "称谓",
            width: 100,
            dataIndex: 'Title',
            sortable: true
        }, {
            text: "部门",
            width: 100,
            dataIndex: 'Department',
            sortable: true
        }, {
            text: "上级职务",
            width: 100,
            dataIndex: 'SuperiorPositon',
            sortable: true
        }, {
            text: "上级姓名",
            width: 100,
            dataIndex: 'SuperiorName',
            sortable: true
        }, {
            text: "Id",
            flex: 1,
            dataIndex: 'Id',
            sortable: false,
            hidden: true
        }, {
            text: "企业Id",
            width: 100,
            dataIndex: 'CompanyId',
            sortable: true,
            hidden: true
        }, {
            text: "企业名称",
            width: 120,
            dataIndex: 'CompanyName',
            sortable: true
        }, {
            text: "联系人Id",
            width: 100,
            dataIndex: 'EmpId',
            sortable: true,
            hidden: true
        }, {
            text: "备注",
            width: 100,
            dataIndex: 'Remark',
            sortable: true
        }]
    },
    creatTbar: function () {
        var me = this;
        me.tbar = [
	        {
	            xtype: "companyComboBox",
	            fieldLabel: "企业名称",
	            name: "CompanyName",
	            labelWidth: 60,
	            width: 260,
	            id: me.txtCompanyNameID
	        }, {
	            xtype: 'employeeComboBox',
	            matchFieldWidth: true,
	            fieldLabel: '联系人姓名:',
	            labelWidth: 80,
	            name: 'EmpName',
	            id: me.txtEmpNameID,
	            width: 200
	        }, ' ', {
	            xtype: 'button',
	            text: '查询',
	            iconCls: 'icon-btn-search',
	            handler: function () {
	                me.clearFilters();
	                var vCompanyName = me.down("#" + me.txtCompanyNameID).getDisplayValue();
	                if (vCompanyName && vCompanyName.length > 0) {
	                    me.addFilter("CompanyName", vCompanyName);
	                }

	                var vEmpName = me.down("#" + me.txtEmpNameID).getDisplayValue();
	                if (vEmpName && vEmpName.length > 0) {
	                    me.addFilter("EmpName", vEmpName);
	                }

	                me.loadByFilter();
	            }
	        }, '->', {
	            xtype: 'button',
	            text: '添加',
	            id: me.btnAddID,
	            iconCls: 'icon-btn-add',
	            handler: function () {
	                var win = me.getForm('SHApp.CompanyManage.CompanyLinkman.Form');
	                win.loadRecord(new CompanyLinkman({ Id: null }));
	                win.Show("添加");
	            }
	        }, ' ', {
	            xtype: 'button',
	            disabled: true,
	            id: me.btnEditID,
	            text: '修改',
	            iconCls: 'icon-btn-edit',
	            handler: function () {
	                var rs = me.getSelectionModel().getSelection();
	                if (rs) {
	                    if (rs.length > 0) {
	                        // rs[0].data.StartDate = formatDate(rs[0].data.StartDate);                           
	                        me.EditData(me.getForm('SHApp.CompanyManage.CompanyLinkman.Form'));
	                    }
	                }
	            }
	        }, ' ', {
	            xtype: 'button',
	            disabled: true,
	            id: me.btnDeleteID,
	            text: '删除',
	            iconCls: 'icon-btn-delete',
	            handler: function () {
	                me.DeleteData();
	            }
	        }
        ]
    }
})

